package com.itheima.shop.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.itheima.shop.entity.Category;
import com.itheima.shop.service.CategoryService;
import com.itheima.shop.service.ProductService;

@Controller
@RequestMapping("/")
public class RootController {
	private final static Logger logger = LoggerFactory.getLogger(RootController.class);
	//快捷改名alt+shift+r
	@Autowired
	private CategoryService categoryService;
	
	@Autowired
	private ProductService sroductService;
	
	
	@Autowired
	private HttpServletRequest request;
	
	@RequestMapping("/header")
	public String head() {
		List<Category> categories = categoryService.findAll();
		if(categories!=null) {
			request.setAttribute("categories", categories);
			logger.info("header.jsp,categories:"+categories);
		}
		return "forward:/header.jsp";
	}
	@RequestMapping("/index")
	public String index() {
		request.setAttribute("hotProducts", sroductService.findHot());
		request.setAttribute("newProducts", sroductService.findNew());
		return "index";
	}
}
